package com.internetCafes.spms.web.tenant.service.impl;

import com.internetCafes.spms.core.generic.GenericDao;
import com.internetCafes.spms.core.generic.GenericServiceImpl;
import com.internetCafes.spms.core.model.pageModel.DataGrid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.internetCafes.spms.web.tenant.dao.TenantRoleInfoMapper;
import com.internetCafes.spms.web.tenant.model.TenantRoleInfo;
import com.internetCafes.spms.web.tenant.service.TenantRoleInfoService;


/**
 * 租户角色信息 TenantRoleInfoService 实现类
 *
 * @author Sunny
 * @email rekeeper2011@hotmail.com
 * @date 2019-10-31 18:09:54
 */
@Service("tenantRoleInfoService")
public class TenantRoleInfoServiceImpl extends GenericServiceImpl<TenantRoleInfo, Long> implements TenantRoleInfoService {

    @Autowired
    private TenantRoleInfoMapper tenantRoleInfoMapper;

    @Override
    public List<TenantRoleInfo> query(Map<String, Object> params) {
        return tenantRoleInfoMapper.selectByParams(params);
    }

    @Override
    public TenantRoleInfo findById(Long id) {
        return tenantRoleInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<TenantRoleInfo> queryByIds(List<Long> ids) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("ids", ids);
        return tenantRoleInfoMapper.selectByParams(params);
    }

    @Override
    public List<TenantRoleInfo> page(Map<String, Object> params, int page, int rows) {
        params.put("page", page);
        params.put("rows", rows);
        return tenantRoleInfoMapper.selectByParams(params);
    }

    @Override
    public long count(Map<String, Object> params) {
        return tenantRoleInfoMapper.countByParams(params);
    }

    @Override
    public TenantRoleInfo findFirst(Map<String, Object> params) {
        List<TenantRoleInfo> list = tenantRoleInfoMapper.selectByParams(params);
        TenantRoleInfo tenantRoleInfo =null;
        if (list != null && list.size() > 0) {
            tenantRoleInfo =list.get(0);
        }
        return tenantRoleInfo;
    }

    @Override
    public int save(TenantRoleInfo tenantRoleInfo) {
        return tenantRoleInfoMapper.insert(tenantRoleInfo);
    }

    @Override
    public int saveBatch(List<TenantRoleInfo> tenantRoleInfoList) {
        return tenantRoleInfoMapper.insertBatch(tenantRoleInfoList);
    }

    @Override
    public int saveSelective(TenantRoleInfo tenantRoleInfo) {
        return tenantRoleInfoMapper.insertSelective(tenantRoleInfo);
    }

    @Override
    public int update(TenantRoleInfo tenantRoleInfo) {
        return tenantRoleInfoMapper.updateByPrimaryKey(tenantRoleInfo);
    }

    @Override
    public int updateSelective(TenantRoleInfo tenantRoleInfo) {
        return tenantRoleInfoMapper.updateByPrimaryKeySelective(tenantRoleInfo);
    }

    @Override
    public int delete(Long id) {
        return tenantRoleInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteBatch(List<Long> ids) {
        return tenantRoleInfoMapper.deleteBatchByPrimaryKey(ids);
    }

    @Override
    public void deleteBatch(Long[] ids) {
        if(ids != null && ids.length > 0){
            for(Long id : ids){
                delete(id);
            }
        }
    }

    @Override
    public GenericDao<TenantRoleInfo, Long> getDao() {
        return tenantRoleInfoMapper;
    }

    /**
	 * DataGrid
	 */
    @Override
    public DataGrid dataGrid(Map<String, Object> params, int pageNo, int pageSize) {

        List<TenantRoleInfo> tenantRoleInfoList = page(params, (pageNo - 1 < 0 ? -1 : pageNo - 1) * pageSize, pageSize);
        long count = count(params);

        DataGrid dg = new DataGrid(tenantRoleInfoList, count, pageSize, pageNo);
        return dg;
    }
}